import Taro, { Component } from '@tarojs/taro'
import { Image, Text, View } from '@tarojs/components'
import './index.scss'
import { formatAmount, getThumbnailConfig, headImg } from "@/utils/utils"

interface IProps {
  list: any
}

export default class Index extends Component<IProps, {}> {
  props: any

  static options = {
    addGlobalClass: true
  }

  //  点击事件
  onClick() {
    const { onClick } = this.props
    if (onClick) {
      onClick()
    }
  }

  render() {
    const { list=[] } = this.props
    return (<View className='order-goods-list' onClick={this.onClick.bind(this)}>
      {list.map(i => {
        return (<View key={i.id} className='goods-item thin-border__b'>
          <Image src={getThumbnailConfig(headImg(i.images), 320, 320)} className='goods-img' lazyLoad/>
          <View className='other-box d-f f-d-c j-c-b'>
            <View className='other-head'>
              <View className='goods-name t-o-e-2'>{i.name}</View>
              {i.specSnap && <View className='attr-name t-o-e'>{i.specSnap}</View>}
            </View>
            <View className='other-foot d-f a-i-b j-c-b'>
              <View className='goods-price bnn-number'>
                <Text className='price-unit'>￥</Text>{formatAmount(i.salePrice)}
              </View>
              <View className='goods-num'>x{i.number}</View>
            </View>
          </View>
        </View>)
      })}
    </View>)
  }
}
